package com.lc.pda.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.parser.ISqlParser;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.lc.pda.handler.MetaHandler;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author NASH.LEE
 */
@Configuration
@EnableTransactionManagement
@MapperScan(value = "com.lc.pda.dao")
public class MybatisPlusConfig {

    /**
     * 创建租户维护处理器对象
     *
     * @return 处理后的租户维护处理器
     */
//    @Bean
//    public SaturnTenantHandler shopTenantHandler() {
//        return new SaturnTenantHandler();
//    }

    /**
     * 分页插件
     *
     * @return
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        // 创建SQL解析器集合
        List<ISqlParser> sqlParserList = new ArrayList<>();
        // 创建租户SQL解析器
//        TenantSqlParser tenantSqlParser = new TenantSqlParser();
        // 设置组合处理器
//        tenantSqlParser.setTenantHandler(tenantHandler);
//        sqlParserList.add(tenantSqlParser);
        paginationInterceptor.setSqlParserList(sqlParserList);
        return paginationInterceptor;
    }

    /**
     * 自动填充功能
     *
     * @return
     */
    @Bean(name = "metaHandler")
    public MetaObjectHandler metaObjectHandler() {
        return new MetaHandler();
    }

}
